We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Mock Model::find -> PHPUnit_Framework_MockObject_BadMethodCallException

While testing with PHPUnit i encountered a problem.

$movieModelMock = $this->getMockBuilder('MoCo\Models\Movie')->getMock();

$movieModelMock->method('find')->willReturn($this->returnValue(null));

$this->assertEquals(null, $movieModelMock->find());

This results in:

PHPUnit_Framework_MockObject_BadMethodCallException

MoCo\Models\Movie is a basic Phalcon model. Nothing fancy.

If someone wants to try to reproduce it: https://github.com/mrBulb/MoCo/tree/develop

To run the tests:

cd tests

../vendor/bin/phpunit

Anyone a idea?



661

Just a status update: PHPUnit cant mock static methods.

$movie = new MovieModel(),

$movie->find(); //Results in self::find() due to the magic __call method...

So my idea is to implement the repository pattern. I wanted to do it anyway because i dont like the ActiveRecord approach.

If someone still has an idea, feel free to comment :)



661

Ok, nevermind.

I'll try codeception with aspectMock first. Implementing a good respository is pretty hard in phalcon.



661
Accepted
answer

Alright. Since i didnt managed to made it work with codeception + aspectMock i decided to implement the repository pattern.

If someone is interessted in the result: https://github.com/mrBulb/MoCo/tree/develop